<template>
    <div id="softwareList">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="职位名称">
          <el-input v-model="formInline.softwareName" placeholder="职位名称"></el-input>
        </el-form-item>
        <el-form-item label="区间查询">
          <el-input v-model="formInline.startTime" placeholder="开始时间"></el-input>
        </el-form-item>
        <el-form-item label="-">
          <el-input v-model="formInline.endTime" placeholder="结束时间"></el-input>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-radio v-model="formInline.audit" label="1">通过</el-radio>
          <el-radio v-model="formInline.audit" label="0">未通过</el-radio>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
      <el-button @click="openSave">添加软件</el-button>
      <el-button @click="deleteSoftware">删除软件</el-button>
      <el-button @click="auditSoftware(1)">审核通过</el-button>
      <el-button @click="auditSoftware(2)">审核不通过</el-button>
      <template>
        <el-table
          :data="tableData"
          border
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection">
          </el-table-column>
          <el-table-column
            prop="softwareId"
            label="软件id">
          </el-table-column>
          <el-table-column
            prop="softwareName"
            label="软件名称">
            <template slot-scope="scope">
              <span v-html="scope.row.softwareName"></span>
            </template>
          </el-table-column>
          <el-table-column
            prop="softwareWeb"
            label="软件官网">
            <template slot-scope="scope">
              <a :href="scope.row.softwareWeb==null?'':scope.row.softwareWeb">
                {{scope.row.softwareWeb==null||scope.row.softwareWeb==''?"暂无官网":scope.row.softwareWeb}}
              </a>
            </template>
          </el-table-column>
          <el-table-column
            prop="softwareId"
            label="软件id">
            <template slot-scope="scope">
              <span v-if="scope.row.softwareAudit==0">审核中</span>
              <span v-if="scope.row.softwareAudit==1">审核通过</span>
              <span v-if="scope.row.softwareAudit==2">审核不通过</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间">
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleEdit( scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="parseInt(number)"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="parseInt(size)"
        layout="total, sizes, prev, pager, next, jumper"
        :total="parseInt(total)">
      </el-pagination>
      <el-dialog title="添加职位" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form :model="form">
            <el-form-item label="职位名称" :label-width="formLabelWidth">
              <el-input v-model="form.softwareName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="软件官网" :label-width="formLabelWidth">
              <el-input v-model="form.softwareWeb" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveSoftware">添加</el-button>
        </div>
      </el-dialog>
      <el-dialog title="修改职位" :visible.sync="flagJob">
        <el-form :model="form">
          <el-form-item label="职位名称" :label-width="formLabelWidth">
            <el-input v-model="form.softwareName" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="软件官网" :label-width="formLabelWidth">
            <el-input v-model="form.softwareWeb" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="flagJob = false">取 消</el-button>
          <el-button type="primary" @click="updateSoftware">修改</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script>
import {findAllSoftwareAdmin,saveSoftware,updateSoftware,deleteSoftware,auditSoftware} from '../../api/way.js'
    export default {
      data(){
        return{
          formLabelWidth: '120px',
          dialogFormVisible:false,
          flagJob:false,
          tableData:[],
          number:1,
          size:5,
          total:0,
          multipleSelection:[],
          form: {
            softwareName: '',
          },
          formInline: {
            softwareName: '',
            startTime: '',
            endTime:'',
            audit:''
          },
        }
      },
      methods: {
        auditSoftware(val){
          let param={
            "ids":this.multipleSelection,
            'paramMap':{
              "audit":val
            }
          }
          auditSoftware(param).then(res=>{
            if (res.code==200){
              this.$message({
                message: res.msg,
                type: 'success'
              });
              this.selectCompany()
            }else {
              this.$message.error(res.msg);
            }
          })
        },
        onSubmit() {
          let  param={
            "current":1,
            "size":this.size,
            paramMap:{
              "softwareName":this.formInline.softwareName,
              "startTime":this.formInline.startTime,
              "endTime":this.formInline.endTime,
              "audit":this.formInline.audit
            }
          }
          findAllSoftwareAdmin(param).then(res=>{
            console.log(res.data);
            this.tableData=res.data.records
            this.total=res.data.total
            this.number=res.data.current
            this.size=res.data.size
          })
        },
        deleteSoftware(){
          let param={"ids":this.multipleSelection}
          deleteSoftware(param).then(res=>{
            if (res.code==200){
              this.$message({
                message: res.msg,
                type: 'success'
              });
              this.selectCompany()
            }else {
              this.$message.error(res.msg);
            }
          })
        },
        openSave(){
          this.form={}
          this.dialogFormVisible=true
        },
        handleEdit( row) {
          this.form={}
          this.form=row
          this.flagJob=true
          console.log(this.form);
        },
        updateSoftware(){
          updateSoftware(this.form).then(res=>{
            if (res.code==200){
              this.$message({
                message: res.msg,
                type: 'success'
              });
              this.selectCompany()
              this.flagJob=false
            }else {
              this.$message.error(res.msg);
            }
          })
        },
        saveSoftware(){
          saveSoftware(this.form).then(res=>{
            if (res.code==200){
              this.$message({
                message: res.msg,
                type: 'success'
              });
              this.selectCompany()
              this.dialogFormVisible=false
            }else {
              this.$message.error(res.msg);
            }
          })
        },
        handleSelectionChange(val) {
          this.multipleSelection=[]
          for (var i in val){
            this.multipleSelection.push(val[i].softwareId)
          }
        },
        handleSizeChange(val) {
          let param={
            "current":this.number,
            "size":val,
            "paramMap":{}
          }
          findAllSoftwareAdmin(param).then(res=>{
            this.tableData=res.data.records
            this.total=res.data.total
            this.number=res.data.current
            this.size=res.data.size
          })
        },
        handleCurrentChange(val) {
          let param={
            "current":val,
            "size":this.size,
            "paramMap":{}
          }
          findAllSoftwareAdmin(param).then(res=>{
            this.tableData=res.data.records
            this.total=res.data.total
            this.number=res.data.current
            this.size=res.data.size
          })
        },
        selectCompany(){
          let  param={
            "current":1,
            "size":this.size,
            paramMap:{}
          }
          findAllSoftwareAdmin(param).then(res=>{
            this.tableData=res.data.records
            this.total=res.data.total
            this.number=res.data.current
            this.size=res.data.size
          })
        }
      },
      mounted() {
        let param={
          "current":this.number,
          "size":this.size,
          "paramMap":{}
        }
        findAllSoftwareAdmin(param).then(res=>{
          this.tableData=res.data.records
          this.total=res.data.total
          this.number=res.data.current
          this.size=res.data.size
        })
      }
    }
</script>

<style scoped>

</style>
